<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="UTF-8">
<title>输入报文展示及修改</title>

<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-table.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/style.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-editable.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/dropzone.css">

</head>

<body>
	<div th:insert="~{header :: copy}"></div>

	<div class="panel panel-default" style="padding-top: 80px;margin-left: 50px;margin-right: 50px;border: 0px">
		<div class="panel-heading" style="background: white;">
			<font size="5px">输入报文展示及修改</font>
		</div>
		<div class="panel-body">
			<div id="toolbar" class="btn-group">
				<button id="btn_add" type="button" class="btn btn-default"
					data-toggle="modal" data-target="#addModel">
					<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				</button>
			</div>
			<table id="table"></table>
		</div>
	</div>

	<div id="addModel" class="modal fade" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content" style="width: 500px; align-self: center;">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true"></button>
					<h4 class="modal-title">
						<i class="icon-pencil"></i> <span id="lblAddTitle"
							style="font-weight: bold">输入报文展示及修改</span>
					</h4>
				</div>
				<div class="modal-body" style="text-align: center;">
					<form id='searchForm' action="apiDefine/saveOrUpdate"
						class="bs-example bs-example-form" role="form"
						style="align-self: center;">
						<div class="input-group">
							<span class="input-group-addon" style="width: 100px"><i
								class="icon-th">API id</i></span> <input type="text" 
								class="form-control" name="apiId" id="msgInConf-apiId" placeholder="abc" 
								onblur="validateLegalNumber('msgInConf-apiId','apiIdSpan')"
								onkeyup="validateLegalNumber('msgInConf-apiId','apiIdSpan')">
							<span class="input-group-addon" id="apiIdSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">参数名</i></span> <input type="text"
								class=" form-control" name="paramName" id="msgInConf-paramName" 
								onblur="validateEmptyContent('msgInConf-paramName','paramNameSpan')"
								onkeyup="validateEmptyContent('msgInConf-paramName','paramNameSpan')">
							<span class="input-group-addon" id="paramNameSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">参数长度</i></span> <input type="text"
								class=" form-control" name="paramLength" id="msgInConf-paramLength" 
								onblur="validateEmptyContent('msgInConf-paramLength','paramLengthSpan')"
								onkeyup="validateEmptyContent('msgInConf-paramLength','paramLengthSpan')">
							<span class="input-group-addon" id="paramLengthSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">父节点</i></span> <input type="text"
								class="form-control" id="msgInConf-parentNode">
							<span class="input-group-addon" id="parentNodeSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">参数注释</i></span> <input type="text"
								class=" form-control" name="paramNote" id="msgInConf-paramNote" 
								onblur="validateEmptyContent('msgInConf-paramNote','paramNoteSpan')"
								onkeyup="validateEmptyContent('msgInConf-paramNote','paramNoteSpan')">
							<span class="input-group-addon" id="paramNoteSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">加密策略</i></span>
							<select style="height: 28px" name = "encryptStrategy" id="msgInConf-encryptStrategy">
							</select>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">参数类型</i></span> 
							<select id="msgInConf-paramType" style="height: 28px"></select>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">是否为空</i></span>
							<select style="height: 28px" name = "isEmpty" id="msgInConf-isEmpty">
								<option value="1">是</option>
								<option value="0" selected="selected">否</option>
							</select>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 100px"><i
								class="icon-th">是否激活</i></span>
							<select style="height: 28px" name = "isActivated" id="msgInConf-isActivated">
								<option value="1">是</option>
								<option value="0" selected="selected">否</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="ID" name="ID" />
					<button type="submit" class="btn btn-primary"
						onclick="saveMsgInConf()" data-dismiss="modal">确定</button>
					<button type="button" class="btn green" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>
	
</body>
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/jquery-ui.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/js/bootstrap-table.js"></script>
<script src="bootstrap/js/bootstrap-editable.min.js"></script>
<script src="bootstrap/js/dropzone.js"></script>
<script src="bootstrap/js/bootstrap-table-editable.js"></script>
<script src="bootstrap/js/gateway.js"></script>
<script type="text/javascript">
	function saveMsgInConf() {
		var apiId = $("#msgInConf-apiId").val();
		var paramName = $("#msgInConf-paramName").val();
		var paramNote = $("#msgInConf-paramNote").val();
		var parentNode = $("#msgInConf-parentNode").val();
		var paramType = $("#msgInConf-paramType").val();
		var isEmpty = $("#msgInConf-isEmpty").val();
		var encryptStrategy = $("#msgInConf-encryptStrategy").val();
		var isActivated = $("#msgInConf-isActivated").val();
		var createTime = $("#msgInConf-createTime").val();
		var updateTime = $("#msgInConf-updateTime").val();
		var paramLength = $("#msgInConf-paramLength").val();

		var data = {
			apiId : apiId,
			paramName : paramName,
			parentNode : parentNode,
			paramNote : paramNote,
			paramType : paramType,
			isEmpty : isEmpty,
			isActivated : isActivated,
			createTime : createTime,
			updateTime : updateTime,
			encryptStrategy : encryptStrategy,
			paramLength : paramLength
		}
		
		saveOrUpdateGateWayConfigurations(data, "/msgInConf/saveOrUpdate", "add");

	}
</script>
<script type="text/javascript">
	$(function() {
		$("#addModel").draggable();//为模态对话框添加拖拽

		var paramTypeArray = new Array();
		
		//加载输入报文类型
		$.ajax({
			type:"get",
			url:"/constants/getMessageTypes",
			async : false,
			success : function(data) {
				var types = "";
				for(var i = 0; i < data.length; i++ ) {
					paramTypeArray[i] = {value:i, text:data[i]};
					types += "<option value='"+ i +"'>" + data[i] +"</option>";
				}
				$("#msgInConf-msgInType").append(types);
			},
			error : function() {
				alert("输入报文类型加载失败!");
			}
		});
		
		var messageTypeArray = new Array();
		
		//加载输入报文参数类型
		$.ajax({
			type:"get",
			url:"/constants/getMesssgeParamTypes",
			async : false,
			success : function(data) {
				var types = "";
				for(var i = 0; i < data.length; i++ ) {
					messageTypeArray[i] = {value:i, text:data[i]};
					types += "<option value='"+ i +"'>" + data[i] +"</option>";
				}
				$("#msgInConf-paramType").append(types);
			},
			error : function() {
				alert("输入报文参数类型加载失败!");
			}
		});
		
		var strategyArray = new Array();
		
		//加载加密策略
		$.ajax({
			type:"get",
			url:"/constants/getEncryptStrategies",
			async : false,
			success : function(data) {
				var types = "";
				for(var i = 0; i < data.length; i++ ) {
					strategyArray[i] = {value:i, text:data[i]};
					types += "<option value='"+ i +"'>" + data[i] +"</option>";
				}
				$("#msgInConf-encryptStrategy").append(types);
			},
			error : function() {
				alert("输入报文参数类型加载失败!");
			}
		});
		
		var curRow = {};
		$('#table').bootstrapTable({
			url : '/msgInConf/listAll',
			pagination : true,
			pageSize : 10,
			pageNumber : 1,
			search : true,
			searchAlign : "right",
			toolbar : "#toolbar",
			columns : [ {
				field : 'id',
				title : 'id'
			}, {
				field : 'apiId',
				title : 'API id',
				editable : {
					type : 'text',
					title : 'API Id',
					validate : function(v) {
						if (!isPositiveInteger(v))
							return 'API Id只能为正整数';

					}
				}
			}, {
				field : 'paramName',
				title : '参数名',
				editable : {
					type : 'text',
					title : '参数名',
					validate : function(v) {
						if (!v)
							return '参数名不能为空';

					}
				}
			}, {
				field : 'parentNode',
				title : '父节点',
				editable : {
					type : 'text',
					title : '父节点',
					validate : function(v) {
						if (!v)
							return '父节点不能为空';

					}
				}
			}, {
				field : 'paramLength',
				title : '参数长度',
				editable : {
					type : 'text',
					title : '参数长度',
					validate : function(v) {
						if (!isPositiveInteger(v))
							return '参数长度只能为正整数';
					}
				}
			}, {
				field : 'paramNote',
				title : '参数注释',
				editable : {
					type : 'text',
					title : '参数注释',
					validate : function(v) {
						if (!v)
							return '参数注释不能为空';

					}
				}
			}, {
				field : 'paramType',
				title : '参数类型',
				editable : {
                    type: 'select',
                    title: '参数类型',
                    source: paramTypeArray
				}
			}, {
				field : 'isEmpty',
				title : '是否为空',
				editable : {
                    type: 'select',
                    title: '是否为空',
                    source:[{value:"1",text:"是"},{value:"0",text:"否"}]
				}
			}, {
				field : 'isActivated',
				title : '是否激活',
				editable : {
                    type: 'select',
                    title: '是否激活',
                    source:[{value:"1",text:"是"},{value:"0",text:"否"}]
				}
			}, {
				field : 'encryptStrategy',
				title : '加密策略',
				editable : {
                    type: 'select',
                    title: '是否加密',
                    source: strategyArray
				}
			}, {
				field : 'formatCreateTime',
				title : '创建时间'
			}, {
				field : 'formatUpdateTime',
				title : '修改时间'
			} ],
			onClickRow : function(row, $element) {
				curRow = row;
			},
			onEditableSave : function(field, row, oldValue, $el) {
				var data = {
					id : row.id,
					apiId : row.apiId,
					msgInType : row.msgInType,
					paramName : row.paramName,
					paramLength : row.paramLength,
					parentNode : row.parentNode,
					paramNote : row.paramNote,
					paramType : row.paramType,
					isEmpty : row.isEmpty,
					isActivated : row.isActivated,
					encryptStrategy : row.encryptStrategy
				}
				
				saveOrUpdateGateWayConfigurations(data, "/msgInConf/saveOrUpdate", "update");

			}
		});
	});
</script>

</html>